package cn.xorange.commons.data.handler;

import cn.hutool.core.util.ReflectUtil;
import cn.xorange.commons.data.core.entity.BaseEntity;

import java.util.Objects;

/**
 * @author : yangjian
 * date : 2024/1/13
 * description :
 */
public interface FillFieldHandle {

    <T extends BaseEntity>void fillInsert(T t);

    <T extends BaseEntity>void fillUpdate(T t);


    default<T> void setFieldValByName(String fieldName, Object val, T t){
        if(Objects.nonNull(val) && ReflectUtil.hasField(t.getClass(),fieldName)){
            Object tVal = ReflectUtil.getFieldValue(t,fieldName);
            if(Objects.isNull(tVal)){
                ReflectUtil.setFieldValue(t,fieldName,val);
            }
        }
    }
}
